home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Util / Md-Mz / MemINIT 2.0.3 Source.cpt / MemINIT 2.0.3 / MemINIT cdev.p < prev    next >
Encoding:
Text File  |  1992-07-13  |  34.6 KB  |  1,198 lines  |  [TEXT/PJMM]

  1. { * MemINIT cdev 2.0.3                                                                            * }
  2. { *                                                                                                     * }
  3. { * The source code to the control panel part of MemINIT.                                    * }
  4. { * Copyright © 1991-1992 Seth LaForge                                                        * }
  5.  
  6.  
  7. unit MemINITcdev;
  8.  
  9. interface
  10.     uses
  11.         Types, GestaltEQU, SANE, Picker;
  12.  
  13.     function main (message, item, numItems, CPid: integer;
  14.                                     event: EventRecord;
  15.                                     cdevValue: Longint;
  16.                                     dlg: DialogPtr): Longint;
  17.  
  18. implementation
  19.  
  20.     const
  21.         undoDev = 9;            {For Undo menu commands}
  22.         cutDev = 10;            {For Cut menu commands}
  23.         copyDev = 11;        {For Copy menu commands}
  24.         pasteDev = 12;        {For Past menu commands}
  25.         clearDev = 13;        {For Clear menu commands}
  26.  
  27.  
  28.         MemPICTBox = 1;
  29.         ShowIcon = 2;
  30.  
  31.         BarActive = 3;
  32.         BarLatency = 5;
  33.         BarLatencyFrame = 6;
  34.         BarLatencyArrows = 7;
  35.         BarTickSpace = 10;
  36.         BarTickSpaceFrame = 11;
  37.         BarTickSpaceArrows = 12;
  38.         BarColor = 15;
  39.         BarDimBox = 16;
  40.         BarSamplePICT = 17;
  41.         BarSampleBox = 18;
  42.  
  43.         PieActive = 19;
  44.         PieLatency = 21;
  45.         PieLatencyFrame = 22;
  46.         PieLatencyArrows = 23;
  47.         PiePanColor = 26;
  48.         PiePieColor = 28;
  49.         PieDimBox = 29;
  50.         PieSampleBox = 30;
  51.  
  52.         HelpButton = 31;
  53.  
  54.  
  55.         MemINITRSRCVarsID = 0;
  56.  
  57.         MemINITColorPICTID = 256;
  58.         MemINITBWPICTID = 257;
  59.  
  60.         AppleColorPICTID = 262;
  61.         AppleBWPICTID = 263;
  62.  
  63.  
  64.         sTrue = -1;
  65.         sFalse = 0;
  66.  
  67.     type
  68.         MIRSRCVars = record
  69.                 ShowIcon, 
  70.  
  71.                 VBLActive: signedByte;
  72.                 VBLTime: integer;
  73.                 UnitSize: longint;
  74.                 BarColor: RGBColor;
  75.  
  76.                 PieActive: signedByte;
  77.                 PieTime: longint;
  78.                 PiePanColor: RGBColor;
  79.                 PiePieColor: RGBColor;
  80.             end;
  81.         MIRSRCVarsP = ^MIRSRCVars;
  82.         MIRSRCVarsH = ^MIRSRCVarsP;
  83.  
  84.         MIMemVars = record
  85.                 rsrc: MIRSRCVars;
  86.  
  87.                 VBLRec: VBLTask;
  88.                 VBLHeap: ptr;
  89.                 ColorAvail, Use32BitAddr, BlackColor: signedByte;
  90.                 MainPMap: PixMapPtr;
  91.                 ColorBits: longint;
  92.                 ColorSize, ColorIndex: integer;
  93.  
  94.                 PieNextUpdate: longint;
  95.                 PiePort: CGrafPort;                        { Actually either grafPort or CGrafPort, depending on whether color QD exists. }
  96.  
  97.                 OldDrawMBar, OldGNEFilter: procPtr;
  98.  
  99.                 GestaltPresent, ScrnSaverPresent: signedByte;
  100.             end;
  101.         MIMemVarsP = ^MIMemVars;
  102.  
  103.         CDEVVars = record
  104.                 MemVars: MIMemVarsP;
  105.                 RSRCVars: MIRSRCVarsH;
  106.             end;
  107.         CDEVVarsP = ^CDEVVars;
  108.         CDEVVarsH = ^CDEVVarsP;
  109.  
  110.         ArrowValueList = array[1..maxint] of OSType;
  111.         ArrowValueListP = ^ArrowValueList;
  112.         ArrowValueListH = ^ArrowValueListP;
  113.  
  114.  
  115.     function ColorQDAvail: boolean;
  116.         var
  117.             theWorld: SysEnvRec;                            { System environment            }
  118.             theErr: OSErr;
  119.     begin
  120.         theErr := SysEnvirons(1, theWorld);            { Check environment                }
  121.         ColorQDAvail := theWorld.hasColorQD;
  122.     end;
  123.  
  124.     function TrapAvailable (trapNum: integer;
  125.                                     tType: TrapType): Boolean;
  126.         const
  127.             _Unimplemented = $A89F;                    { Unimplemented trap                }
  128.         var
  129.             theWorld: SysEnvRec;
  130.             temp: OSErr;
  131.     begin
  132.         temp := SysEnvirons(1, theWorld);
  133.  
  134.         if (tType = ToolTrap) and ((theWorld.machineType < envMachUnknown) or ((theWorld.machineType > envMachUnknown) and (theWorld.machineType < envMacII))) then
  135.             begin
  136.                 trapNum := BAND(trapNum, $3FF);        { Traps numbers are 10 bits long    }
  137.  
  138.                 if trapNum > $1FF then
  139.                     begin                                    { Traps only go up to 0x1FF on        }
  140.                         TrapAvailable := FALSE;                {   these machines                    }
  141.                         Exit(TrapAvailable);
  142.                     end;
  143.             end;
  144.  
  145.         { Compare the address of this trap with that of the    }
  146.         { unimplemented trap                                        }
  147.         TrapAvailable := NGetTrapAddress(trapNum, tType) <> GetTrapAddress(_Unimplemented);
  148.     end;
  149.  
  150.     procedure WasteEvent;
  151.         var
  152.             theEvent: eventRecord;
  153.             dummy: boolean;
  154.     begin
  155.         dummy := GetNextEvent(0, theEvent);
  156.     end;
  157.  
  158.     const
  159.         ArrowValuesType = 'ArVl';
  160.  
  161.     function GetVal (FromStr: OSType): real;
  162.     begin
  163.         if FromStr = 'None' then
  164.             GetVal := 0
  165.         else
  166.             GetVal := Str2Num(FromStr);
  167.     end;
  168.  
  169. { SetArrowValuebyNum }
  170. { Sets the static text of an arrow control by comparing values with a real number and inserting the closest match. }
  171.     procedure SetArrowValuebyNum (theDialog: DialogPtr;
  172.                                     itemNumber: integer;
  173.                                     theNumber: real;
  174.                                     ValuesID: integer);
  175.         var
  176.             itemType: integer;
  177.             itemHandle: handle;
  178.             dispRect: rect;
  179.             theArrowValues: ArrowValueListH;
  180.             numValues, itemCtr: integer;
  181.             ItemVal: real;
  182.     begin
  183.         theArrowValues := ArrowValueListH(GetResource(ArrowValuesType, ValuesID));
  184.         numValues := GetHandleSize(handle(theArrowValues)) div 4;
  185.         for itemCtr := 1 to numValues do
  186.             if GetVal(theArrowValues^^[itemCtr]) >= theNumber then
  187.                 Leave;
  188.         if itemCtr > 1 then
  189.             if theNumber < (GetVal(theArrowValues^^[itemCtr - 1]) + GetVal(theArrowValues^^[itemCtr])) / 2 then
  190.                 itemCtr := itemCtr - 1;        { If the number is less than the average of a larger number and a smaller number, use the smaller. }
  191.         GetDItem(theDialog, itemNumber, itemType, itemHandle, dispRect);
  192.         SetIText(itemHandle, theArrowValues^^[itemCtr]);
  193.     end;
  194.  
  195.     function FindArrowIndex (theDialog: DialogPtr;
  196.                                     itemNumber: integer;
  197.                                     ValuesID: integer): integer;
  198.         var
  199.             itemType: integer;
  200.             itemHandle: handle;
  201.             dispRect: rect;
  202.             theArrowValues: ArrowValueListH;
  203.             numValues, itemCtr: integer;
  204.             itemText: str255;
  205.     begin
  206.         theArrowValues := ArrowValueListH(GetResource(ArrowValuesType, ValuesID));
  207.         numValues := GetHandleSize(handle(theArrowValues)) div 4;
  208.         GetDItem(theDialog, itemNumber, itemType, itemHandle, dispRect);
  209.         GetIText(itemHandle, itemText);
  210.         for itemCtr := 1 to numValues do
  211.             if theArrowValues^^[itemCtr] = itemText then
  212.                 begin
  213.                     FindArrowIndex := itemCtr;
  214.                     exit(FindArrowIndex);
  215.                 end;
  216.         FindArrowIndex := 0;
  217.     end;
  218.  
  219.     function ArrowHit (theDialog: DialogPtr;
  220.                                     itemNumber, textItemNumber: integer;
  221.                                     ValuesID: integer;
  222.                                     var theEvent: EventRecord;
  223.                                     procedure ChangeProc (theDialog: DialogPtr;
  224.                                                                     itemNumber: integer)): boolean;             { Returns true if item changed. }
  225.         const
  226.             StartSpeed = 20;
  227.             Speed2 = 10;
  228.             FlipsB4Increase = 3;
  229.             NowhereIcon = 259;
  230.         var
  231.             curDir, nowDir: (nowhere, up, down);
  232.             itemType: integer;
  233.             itemHandle, TextHandle: handle;
  234.             TextRect, ArrowRect, bigRect: rect;
  235.             theArrowValues: ArrowValueListH;
  236.             numValues, startIndex, curIndex: integer;
  237.             curSpeed, nextChange: longint;
  238.             SpeedCtr: integer;
  239.             curPoint: point;
  240.             curPICT: PicHandle;
  241.         label
  242.             1;
  243.     begin
  244.         theArrowValues := ArrowValueListH(GetResource(ArrowValuesType, ValuesID));
  245.         numValues := GetHandleSize(handle(theArrowValues)) div 4;
  246.  
  247.         GetDItem(theDialog, itemNumber, itemType, itemHandle, ArrowRect);
  248.         GetDItem(theDialog, textItemNumber, itemType, TextHandle, TextRect);
  249.  
  250.         startIndex := FindArrowIndex(theDialog, textItemNumber, ValuesID);
  251.         curIndex := startIndex;
  252.  
  253.         curDir := nowhere;
  254.         SetRect(bigRect, -32768, -32768, 32767, 32767);            { For restoring full clip rgn. }
  255.         curPoint := theEvent.where;
  256.         GlobalToLocal(curPoint);
  257.  
  258.         repeat
  259.             nowDir := nowhere;
  260.             if PtInRect(curPoint, ArrowRect) then
  261.                 if curPoint.v <= (ArrowRect.top + ArrowRect.bottom) div 2 then
  262.                     nowDir := up
  263.                 else
  264.                     nowDir := down;
  265.             if curDir <> nowDir then
  266.                 begin
  267.                     curPICT := GetPicture(NowhereIcon + ord(nowDir));
  268.                     HNoPurge(handle(curPICT));
  269.                     DrawPicture(curPICT, ArrowRect);
  270.                     HPurge(handle(curPICT));
  271.                     curSpeed := StartSpeed;
  272.                     nextChange := 0;
  273.                     SpeedCtr := FlipsB4Increase;
  274.                     curDir := nowDir;
  275.                 end;
  276.  
  277.             if (curDir <> nowhere) and (TickCount >= nextChange) then        { Time to actually do something! }
  278.                 begin
  279.                     if curDir = up then
  280.                         if curIndex >= numValues then
  281.                             goto 1                                    { There's no room to go up! }
  282.                         else
  283.                             curIndex := curIndex + 1
  284.                     else { if curDir = down then }
  285.                         if curIndex <= 1 then
  286.                             goto 1                                    { There's no room to go down! }
  287.                         else
  288.                             curIndex := curIndex - 1;
  289.  
  290.                     SpeedCtr := SpeedCtr - 1;
  291.                     if SpeedCtr = 0 then
  292.                         curSpeed := Speed2;
  293.                     nextChange := TickCount + curSpeed;
  294.  
  295.                     SetIText(TextHandle, theArrowValues^^[curIndex]);
  296.                     ClipRect(TextRect);
  297.                     UpdtDialog(theDialog, theDialog^.clipRgn);
  298.                     ClipRect(BigRect);
  299.                     ChangeProc(theDialog, textItemNumber);
  300.  
  301.                 end;
  302.  
  303. 1:
  304.             GetMouse(curPoint);
  305.         until not stillDown;
  306.  
  307.         if curDir <> nowhere then
  308.             begin
  309.                 curPICT := GetPicture(NowhereIcon);
  310.                 HNoPurge(handle(curPICT));
  311.                 DrawPicture(curPICT, ArrowRect);
  312.                 HPurge(handle(curPICT));
  313.             end;
  314.         ArrowHit := curIndex <> StartIndex;
  315.     end;
  316.  
  317.     procedure CPenNormal;
  318.         var
  319.             theColor: RGBColor;
  320.     begin
  321.         if ColorQDAvail then
  322.             begin
  323.                 with theColor do
  324.                     begin
  325.                         red := $FFFF;
  326.                         green := $FFFF;
  327.                         blue := $FFFF;
  328.                     end;
  329.                 RGBBackColor(theColor);
  330.                 with theColor do
  331.                     begin
  332.                         red := $0000;
  333.                         green := $0000;
  334.                         blue := $0000;
  335.                     end;
  336.                 RGBForeColor(theColor);
  337.             end;
  338.     end;
  339.  
  340.     procedure DrawPICTItem (theDialog: DialogPtr;
  341.                                     itemNumber: integer);
  342.         var
  343.             thePICTID: integer;
  344.             thePicture: PicHandle;
  345.             itemType: integer;            {For GetDItem}
  346.             itemHandle: Handle;            {For GetDItem}
  347.             dispRect, globRect: Rect;                {For GetDItem}
  348.             theDevice: GDHandle;
  349.     begin
  350.         GetDItem(theDialog, itemNumber, itemType, itemHandle, dispRect);    {Set some text}
  351.  
  352.         thePICTID := MemINITBWPICTID;
  353.         if ColorQDAvail then
  354.             begin
  355.                 globRect := dispRect;
  356.                 LocalToGlobal(globRect.topLeft);
  357.                 LocalToGlobal(globRect.botRight);
  358.                 theDevice := GetMaxDevice(globRect);
  359.                 if (theDevice <> nil) & (theDevice^^.gdPMap^^.PixelSize >= 4) then
  360.                     thePICTID := MemINITColorPICTID
  361.             end;
  362.  
  363.         thePicture := GetPicture(thePICTID);
  364.         HNoPurge(handle(thePicture));
  365.         dispRect.right := dispRect.left + (thePicture^^.picFrame.right - thePicture^^.picFrame.left);
  366.         dispRect.bottom := dispRect.top + (thePicture^^.picFrame.bottom - thePicture^^.picFrame.top);
  367.         DrawPicture(thePicture, dispRect);
  368.         HPurge(handle(thePicture));
  369.     end;
  370.  
  371.     procedure DrawFrameItem (theDialog: DialogPtr;
  372.                                     itemNumber: integer;
  373.                                     MyVars: CDEVVarsH);
  374.         var
  375.             itemType: integer;            {For GetDItem}
  376.             itemHandle: Handle;            {For GetDItem}
  377.             dispRect: Rect;                {For GetDItem}
  378.     begin
  379.         GetDItem(theDialog, itemNumber, itemType, itemHandle, dispRect);
  380.         FrameRect(dispRect);
  381.     end;
  382.  
  383.     procedure DrawGrayItem (theDialog: DialogPtr;
  384.                                     itemNumber: integer;
  385.                                     MyVars: CDEVVarsH);
  386.         var
  387.             itemType: integer;            {For GetDItem}
  388.             itemHandle: Handle;            {For GetDItem}
  389.             dispRect: Rect;                {For GetDItem}
  390.             grayPat: pattern;
  391.             SavePen: PenState;
  392.     begin
  393.         GetPenState(SavePen);
  394.         GetDItem(theDialog, itemNumber, itemType, itemHandle, dispRect);
  395.         StuffHex(@grayPat, 'AA55AA55AA55AA55');
  396.         PenPat(grayPat);
  397.         PenMode(patBIC);
  398.         PaintRect(dispRect);
  399.         SetPenState(SavePen);
  400.     end;
  401.  
  402.     function ColorItemHit (theDialog: DialogPtr;
  403.                                     itemNumber: integer;
  404.                                     var theColor: RGBColor;
  405.                                     Prompt: str255;
  406.                                     var theEvent: EventRecord): boolean;
  407.         var
  408.             itemType: integer;            {For GetDItem}
  409.             itemHandle: Handle;            {For GetDItem}
  410.             dispRect: Rect;                {For GetDItem}
  411.             hilited: boolean;
  412.             curMouse: point;
  413.     begin
  414.         ColorItemHit := false;
  415.  
  416.         GetDItem(theDialog, itemNumber, itemType, itemHandle, dispRect);
  417.         insetRect(dispRect, 1, 1);
  418.         PenSize(2, 2);
  419.         PenMode(patXOR);
  420.  
  421.         hilited := false;
  422.         curMouse := theEvent.where;
  423.         GlobalToLocal(curMouse);
  424.         repeat
  425.             if PtInRect(curMouse, dispRect) <> hilited then
  426.                 begin
  427.                     FrameRect(dispRect);
  428.                     hilited := not hilited;
  429.                 end;
  430.             GetMouse(curMouse);
  431.         until not StillDown;
  432.  
  433.         if hilited then
  434.             begin
  435.                 FrameRect(dispRect);
  436.  
  437.                 setPt(curMouse, -1, -1);        { Used for GetColor, signal to display on best screen. }
  438.                 if ColorQDAvail then
  439.                     ColorItemHit := GetColor(curMouse, Prompt, theColor, theColor)
  440.                 else
  441.                     SysBeep(5);
  442.             end;
  443.  
  444.         PenSize(1, 1);
  445.     end;
  446.  
  447.     procedure DrawColorItem (theDialog: DialogPtr;
  448.                                     itemNumber: integer;
  449.                                     theColor: RGBColor);
  450.         var
  451.             itemType: integer;            {For GetDItem}
  452.             itemHandle: Handle;            {For GetDItem}
  453.             dispRect, globRect: Rect;                {For GetDItem}
  454.             theDevice: GDHandle;
  455.     begin
  456.         GetDItem(theDialog, itemNumber, itemType, itemHandle, dispRect);
  457.         FrameRect(dispRect);
  458.         InsetRect(dispRect, 1, 1);
  459.         EraseRect(dispRect);
  460.         if ColorQDAvail then
  461.             begin
  462.                 globRect := dispRect;
  463.                 LocalToGlobal(globRect.topLeft);
  464.                 LocalToGlobal(globRect.botRight);
  465.                 theDevice := GetMaxDevice(globRect);
  466.                 if (theDevice <> nil) & (theDevice^^.gdPMap^^.PixelSize >= 1) then
  467.                     RGBForeColor(theColor);
  468.             end;
  469.         InsetRect(dispRect, 2, 2);
  470.         PaintRect(dispRect);
  471.         CPenNormal;
  472.     end;
  473.  
  474.     procedure DrawBarColorItem (theDialog: DialogPtr;
  475.                                     itemNumber: integer;
  476.                                     MyVars: CDEVVarsH);
  477.     begin
  478.         DrawColorItem(theDialog, itemNumber, myVars^^.RSRCVars^^.BarColor);
  479.     end;
  480.  
  481.     procedure DrawPiePanColorItem (theDialog: DialogPtr;
  482.                                     itemNumber: integer;
  483.                                     MyVars: CDEVVarsH);
  484.     begin
  485.         DrawColorItem(theDialog, itemNumber, myVars^^.RSRCVars^^.PiePanColor);
  486.     end;
  487.  
  488.     procedure DrawPiePieColorItem (theDialog: DialogPtr;
  489.                                     itemNumber: integer;
  490.                                     MyVars: CDEVVarsH);
  491.     begin
  492.         DrawColorItem(theDialog, itemNumber, myVars^^.RSRCVars^^.PiePieColor);
  493.     end;
  494.  
  495.     procedure DrawBarSample (theDialog: DialogPtr;
  496.                                     itemNumber: integer;
  497.                                     MyVars: CDEVVarsH);
  498.         var
  499.             itemType: integer;            {For GetDItem}
  500.             itemHandle: Handle;            {For GetDItem}
  501.             dispRect, globRect: Rect;                {For GetDItem}
  502.             theDevice: GDHandle;
  503.     begin
  504.         if myVars^^.RSRCVars^^.VBLActive = sTrue then
  505.             begin
  506.                 GetDItem(theDialog, itemNumber, itemType, itemHandle, dispRect);
  507.                 EraseRect(dispRect);
  508.                 if ColorQDAvail then
  509.                     begin
  510.                         globRect := dispRect;
  511.                         LocalToGlobal(globRect.topLeft);
  512.                         LocalToGlobal(globRect.botRight);
  513.                         theDevice := GetMaxDevice(globRect);
  514.                         if (theDevice <> nil) & (theDevice^^.gdPMap^^.PixelSize >= 1) then
  515.                             RGBForeColor(myVars^^.RSRCVars^^.BarColor);
  516.                     end;
  517.                 dispRect.right := dispRect.left + (dispRect.right - dispRect.left) div 3 * 2;
  518.                 PaintRect(dispRect);
  519.                 CPenNormal;
  520.             end;
  521.     end;
  522.  
  523.     procedure DrawPieSample (theDialog: DialogPtr;
  524.                                     itemNumber: integer;
  525.                                     MyVars: CDEVVarsH);
  526.  
  527.         var
  528.             itemType: integer;            {For GetDItem}
  529.             itemHandle: Handle;            {For GetDItem}
  530.             dispRect, globRect: Rect;                {For GetDItem}
  531.             theDevice: GDHandle;
  532.             SavePen: PenState;
  533.  
  534.             thePICTID: integer;
  535.             thePicture: PicHandle;
  536.     begin
  537.         GetDItem(theDialog, itemNumber, itemType, itemHandle, dispRect);
  538.         if myVars^^.RSRCVars^^.PieActive = sTrue then
  539.             begin
  540.                 FrameOval(dispRect);
  541.                 GetPenState(SavePen);
  542.                 if ColorQDAvail then
  543.                     begin
  544.                         globRect := dispRect;
  545.                         LocalToGlobal(globRect.topLeft);
  546.                         LocalToGlobal(globRect.botRight);
  547.                         theDevice := GetMaxDevice(globRect);
  548.                         if (theDevice <> nil) & (theDevice^^.gdPMap^^.PixelSize >= 4) then
  549.                             begin
  550.                                 RGBForeColor(myVars^^.RSRCVars^^.PiePieColor);
  551.                                 RGBBackColor(myVars^^.RSRCVars^^.PiePanColor);
  552.                             end;
  553.                     end;
  554.                 insetRect(dispRect, 1, 1);
  555.                 EraseOval(dispRect);
  556.                 PaintArc(dispRect, 0, 240);
  557.                 CPenNormal;
  558.                 SetPenState(SavePen);
  559.             end
  560.         else
  561.             begin
  562.                 EraseRect(dispRect);
  563.  
  564.                 thePICTID := AppleBWPICTID;
  565.                 if ColorQDAvail then
  566.                     begin
  567.                         globRect := dispRect;
  568.                         LocalToGlobal(globRect.topLeft);
  569.                         LocalToGlobal(globRect.botRight);
  570.                         theDevice := GetMaxDevice(globRect);
  571.                         if (theDevice <> nil) & (theDevice^^.gdPMap^^.PixelSize >= 4) then
  572.                             thePICTID := AppleColorPICTID
  573.                     end;
  574.  
  575.                 thePicture := GetPicture(thePICTID);
  576.                 HNoPurge(handle(thePicture));
  577.                 with thePicture^^.picFrame do
  578.                     begin
  579.                         dispRect.left := (dispRect.left + dispRect.right - (right - left)) div 2;
  580.                         dispRect.top := (dispRect.top + dispRect.bottom - (bottom - top)) div 2;
  581.                         dispRect.right := dispRect.left + (right - left);
  582.                         dispRect.bottom := dispRect.top + (bottom - top);
  583.                     end;
  584.                 DrawPicture(thePicture, dispRect);
  585.                 HPurge(handle(thePicture));
  586.             end;
  587.     end;
  588.  
  589.     function ItemVisible (theDialog: DialogPtr;
  590.                                     theItem: integer): boolean;
  591.         var
  592.             itemType: integer;
  593.             itemHandle: handle;
  594.             dispRect: rect;
  595.     begin
  596.         GetDItem(theDialog, theItem, itemType, itemHandle, dispRect);
  597.         ItemVisible := SectRect(dispRect, theDialog^.PortRect, dispRect);
  598.     end;
  599.  
  600.     function GetScreenRect: rect;
  601.         var
  602.             WManagerPort: GrafPtr;
  603.     begin
  604.         GetWMgrPort(WManagerPort);
  605.         GetScreenRect := WManagerPort^.portRect;
  606.     end;
  607.  
  608.     function Min (N1, N2: longint): longint;
  609.     begin
  610.         if N1 <= N2 then
  611.             Min := N1
  612.         else
  613.             Min := N2;
  614.     end;
  615.  
  616.     function Max (N1, N2: longint): longint;
  617.     begin
  618.         if N1 >= N2 then
  619.             Max := N1
  620.         else
  621.             Max := N2;
  622.     end;
  623.  
  624.     const
  625. {•  OK = 1;•}
  626.         OKFrame = 2;
  627.         MemINITPict = 3;
  628.         TextBox = 4;
  629.         TextScrollBar = 5;
  630.  
  631.     procedure DrawOKFrame (theDialog: DialogPtr;
  632.                                     theItem: integer);
  633.         var
  634.             itemType: integer;
  635.             itemHandle: Handle;
  636.             dispRect: Rect;
  637.     begin
  638.         GetDItem(theDialog, theItem, itemType, itemHandle, dispRect);
  639.         PenSize(3, 3);
  640.         FrameRoundRect(dispRect, 16, 16);
  641.         PenSize(1, 1);
  642.     end;
  643.  
  644.     procedure DrawTextBox (theDialog: DialogPtr;
  645.                                     theItem: integer);
  646.         var
  647.             itemType: integer;
  648.             itemHandle: Handle;
  649.             dispRect: Rect;
  650.     begin
  651.         GetDItem(theDialog, theItem, itemType, itemHandle, dispRect);
  652.         FrameRect(dispRect);
  653.         TEUpdate(dispRect, TEHandle(WindowPeek(theDialog)^.refCon));
  654.     end;
  655.  
  656.     procedure HelpScrollControlAction (theControl: ControlHandle;
  657.                                     thePart: integer);
  658.         var
  659.             theDialog: WindowPeek;
  660.             OldCtlValue, NewCtlValue: integer;
  661.             TextTE: TEHandle;
  662.     begin
  663.         GetPort(GrafPtr(theDialog));
  664.         TextTE := TEHandle(theDialog^.RefCon);
  665.         OldCtlValue := theControl^^.ContrlRfCon;
  666.         NewCtlValue := GetCtlValue(theControl);
  667.         if thePart = InUpButton then
  668.             NewCtlValue := max(GetCtlMin(theControl), NewCtlValue - 1)
  669.         else if thePart = InDownButton then
  670.             NewCtlValue := min(GetCtlMax(theControl), NewCtlValue + 1)
  671.         else if thePart = InPageUp then
  672.             NewCtlValue := max(GetCtlMin(theControl), NewCtlValue - ((TextTE^^.viewRect.bottom - TextTE^^.viewRect.top) div TextTE^^.lineHeight - 1))
  673.         else if thePart = InPageDown then
  674.             NewCtlValue := min(GetCtlMax(theControl), NewCtlValue + ((TextTE^^.viewRect.bottom - TextTE^^.viewRect.top) div TextTE^^.lineHeight - 1));
  675.         if NewCtlValue <> GetCtlValue(theControl) then
  676.             SetCtlValue(theControl, NewCtlValue);
  677.         TEScroll(0, (OldCtlValue - NewCtlValue) * TextTE^^.lineHeight, TextTE);
  678.         theControl^^.ContrlRfCon := GetCtlValue(theControl);
  679.     end;
  680.  
  681.     function HelpFilter (theDialog: DialogPtr;
  682.                                     var theEvent: EventRecord;
  683.                                     var itemNumber: integer): boolean;
  684.         const
  685.             crCode = 13;
  686.             enterCode = 3;
  687.         var
  688.             itemType: integer;
  689.             itemHandle: Handle;
  690.             dispRect: Rect;
  691.             PartHit: integer;
  692.             HitPt: point;
  693.             ignoreLong: longint;
  694.     begin
  695.         HelpFilter := false;
  696.         if theEvent.what = MouseDown then
  697.             begin
  698.                 SetPort(theDialog);
  699.                 HitPt := theEvent.where;
  700.                 GlobalToLocal(HitPt);
  701.                 GetDItem(theDialog, TextScrollBar, itemType, itemHandle, dispRect);
  702.                 if ptInRect(HitPt, dispRect) then
  703.                     begin
  704.                         HelpFilter := true;
  705.  
  706.                         ControlHandle(itemHandle)^^.ContrlRfCon := GetCtlValue(ControlHandle(itemHandle));
  707.                         PartHit := TestControl(ControlHandle(itemHandle), HitPt);
  708.                         if PartHit <> 0 then
  709.                             if PartHit <> InThumb then
  710.                                 PartHit := TrackControl(ControlHandle(itemHandle), HitPt, @HelpScrollControlAction)
  711.                             else
  712.                                 begin
  713.                                     PartHit := TrackControl(ControlHandle(itemHandle), HitPt, nil);
  714.                                     HelpScrollControlAction(ControlHandle(itemHandle), PartHit);
  715.                                 end;
  716.                     end;
  717.             end
  718.         else if theEvent.what = keyDown then
  719.             if (theEvent.message mod 256) in [crCode, enterCode] then
  720.                 begin
  721.                 {user pressed Return or Enter}
  722.                     GetDItem(theDialog, OK, itemType, itemHandle, dispRect);
  723.                     HiliteControl(ControlHandle(itemHandle), 1); {make it look...}
  724.                     Delay(5, ignoreLong); {...like the OK button was hit}
  725.                     HiliteControl(ControlHandle(itemHandle), 0);
  726.  
  727.                     HelpFilter := TRUE; {dialog is over}
  728.                     itemNumber := OK; {have ModalDialog return that the user hit OK}
  729.                 end;
  730.     end;
  731.  
  732. {This procedure puts up an about box and brags about us.}
  733.     procedure DoHelp;
  734.         const
  735.             HelpDLOGID = 256;
  736.             HelpTEXTID = 256;
  737.         var
  738.             OldPort: GrafPtr;
  739.             theDialog: DialogPtr;
  740.             DialogPt: point;
  741.             Done: boolean;
  742.  
  743.             itemType: integer;
  744.             itemHandle: Handle;
  745.             dispRect: Rect;
  746.  
  747.             TextTE: TEHandle;
  748.             theHelpText: handle;
  749.             NewCtlMax: integer;
  750.  
  751.             itemhit: integer;
  752.     begin
  753.         GetPort(OldPort);
  754.  
  755.         theDialog := GetNewDialog(HelpDLOGID, nil, WindowPtr(-1));    {Get our dialog from the resource}
  756.         dispRect := GetScreenRect;
  757.         DialogPt.h := (dispRect.right - (theDialog^.portRect.right - theDialog^.portRect.left)) div 2;
  758.         DialogPt.v := (dispRect.bottom - (theDialog^.portRect.bottom - theDialog^.portRect.top)) div 2;
  759.         MoveWindow(theDialog, DialogPt.h, DialogPt.v, True);    {Center our dialog. }
  760.         SetPort(theDialog);                                                {Set the port to our dialog}
  761.         TextFont(geneva);                                                {Set the font}
  762.         TextSize(9);                                                        {Set the font size}
  763.  
  764.         GetDItem(theDialog, MemINITPict, itemType, itemHandle, dispRect);
  765.         SetDItem(theDialog, MemINITPict, itemType, @DrawPICTItem, dispRect);
  766.  
  767.         GetDItem(theDialog, OKFrame, itemType, itemHandle, dispRect);
  768.         SetDItem(theDialog, OKFrame, itemType, @DrawOKFrame, dispRect);
  769.  
  770.         GetDItem(theDialog, TextBox, itemType, itemHandle, dispRect);
  771.         SetDItem(theDialog, TextBox, itemType, @DrawTextBox, dispRect);
  772.         InsetRect(dispRect, 6, 4);
  773.         TextTE := TENew(dispRect, dispRect);
  774.         theHelpText := GetResource('TEXT', HelpTEXTID);
  775.         if theHelpText <> nil then
  776.             begin
  777.                 HLock(theHelpText);
  778.                 TESetText(theHelpText^, GetHandleSize(theHelpText), TextTE);        { Makes a copy of the text. }
  779.                 HUnLock(theHelpText);
  780.                 ReleaseResource(theHelpText);
  781.  
  782.                 NewCtlMax := TextTE^^.nLines - ((TextTE^^.viewRect.bottom - TextTE^^.viewRect.top) div TextTE^^.lineHeight);
  783.                 GetDItem(theDialog, TextScrollBar, itemType, itemHandle, dispRect);
  784.                 if NewCtlMax >= 0 then
  785.                     SetCtlMax(ControlHandle(itemHandle), NewCtlMax);
  786.             end;
  787.         WindowPeek(theDialog)^.RefCon := longint(TextTE);
  788.  
  789.         ShowWindow(theDialog);
  790.  
  791.         Done := false;
  792.         repeat
  793.             Modaldialog(@HelpFilter, itemhit);
  794.             case itemhit of
  795.                 OK: 
  796.                     Done := true;
  797.             end;
  798.         until done;
  799.  
  800.         TEDispose(TextTE);
  801.  
  802.         DisposDialog(theDialog);                        {Take down our dialog}
  803.         SetPort(OldPort);
  804.     end;
  805.  
  806.     procedure UpdateGrays (theDialog: DialogPtr;
  807.                                     numItems: integer;
  808.                                     MyVars: CDEVVarsH);
  809.         var
  810.             itemType: integer;
  811.             itemHandle: handle;
  812.             dispRect: rect;
  813.             NewActivate: boolean;
  814.     begin
  815.  
  816. { Do bar section. }
  817.         NewActivate := MyVars^^.RSRCVars^^.VBLActive <> sFalse;
  818.         if NewActivate <> (not ItemVisible(theDialog, numItems + BarDimBox)) then
  819.             if NewActivate then
  820.                 HideDItem(theDialog, numItems + BarDimBox)            { Will invalidate for us. }
  821.             else
  822.                 begin
  823.                     ShowDItem(theDialog, numItems + BarDimBox);
  824.                     DrawGrayItem(theDialog, numItems + BarDimBox, MyVars);
  825.                     GetDItem(theDialog, numItems + BarDimBox, itemType, itemHandle, dispRect);
  826.                     ValidRect(dispRect);
  827.                 end;
  828.  
  829. { Do pie section. }
  830.         NewActivate := myVars^^.RSRCVars^^.PieActive <> sFalse;
  831.         if NewActivate <> not ItemVisible(theDialog, numItems + PieDimBox) then
  832.             if NewActivate then
  833.                 HideDItem(theDialog, numItems + PieDimBox)            { Will invalidate for us. }
  834.             else
  835.                 begin
  836.                     ShowDItem(theDialog, numItems + PieDimBox);
  837.                     DrawGrayItem(theDialog, numItems + PieDimBox, MyVars);
  838.                     GetDItem(theDialog, numItems + PieDimBox, itemType, itemHandle, dispRect);
  839.                     ValidRect(dispRect);
  840.                 end;
  841.  
  842.     end;
  843.  
  844.     function InitItems (theDialog: DialogPtr;
  845.                                     numItems: integer): CDEVVarsH;
  846.         const
  847.             OurSelector = 'MemV';
  848.         var
  849.             itemType: integer;            {For GetDItem}
  850.             itemHandle: Handle;            {For GetDItem}
  851.             dispRect: Rect;                {For GetDItem}
  852.             myErr: OSErr;
  853.             MyVars: CDEVVarsH;
  854.             MemVars: MIMemVarsP;
  855.             RSRCVars: MIRSRCVarsH;
  856.             aStr: str255;
  857.     begin
  858.  
  859.         MyVars := CDEVVarsH(NewHandle(sizeof(CDEVVars)));
  860.         if MyVars = nil then
  861.             begin
  862.                 InitItems := nil;            { We won't continue... }
  863.                 exit(InitItems);
  864.             end;
  865.         InitItems := MyVars;
  866.         myErr := Gestalt(OurSelector, longint(MemVars));        { The glue will catch us if Gestalt isn't implemented. }
  867.         if myErr <> noErr then
  868.             MemVars := nil;
  869.         MyVars^^.MemVars := MemVars;
  870.  
  871.         RSRCVars := MIRSRCVarsH(GetResource('MVar', MemINITRSRCVarsID));
  872.         MyVars^^.RSRCVars := RSRCVars;
  873.  
  874.  
  875.         GetDItem(theDialog, numItems + ShowIcon, itemType, itemHandle, dispRect);
  876.         if RSRCVars^^.ShowIcon = sFalse then
  877.             SetCtlValue(ControlHandle(itemHandle), 0)
  878.         else
  879.             SetCtlValue(ControlHandle(itemHandle), 1);
  880.  
  881.  
  882.         GetDItem(theDialog, numItems + BarActive, itemType, itemHandle, dispRect);
  883.         if RSRCVars^^.VBLActive = sFalse then
  884.             SetCtlValue(ControlHandle(itemHandle), 0)
  885.         else
  886.             SetCtlValue(ControlHandle(itemHandle), 1);
  887.  
  888.         SetArrowValuebyNum(theDialog, numItems + BarLatency, RSRCVars^^.VBLTime / 60, BarLatencyArrows);
  889.         SetArrowValuebyNum(theDialog, numItems + BarTickSpace, RSRCVars^^.UnitSize / 1024, BarTickSpaceArrows);
  890.  
  891.         GetDItem(theDialog, numItems + PieActive, itemType, itemHandle, dispRect);
  892.         if RSRCVars^^.PieActive = sFalse then
  893.             SetCtlValue(ControlHandle(itemHandle), 0)
  894.         else
  895.             SetCtlValue(ControlHandle(itemHandle), 1);
  896.  
  897.         SetArrowValuebyNum(theDialog, numItems + PieLatency, RSRCVars^^.PieTime / 60, PieLatencyArrows);
  898.  
  899.         HideDItem(theDialog, numItems + BarDimBox);            { Force UpdateGrays to deactivate text... }
  900.         HideDItem(theDialog, numItems + PieDimBox);
  901.         UpdateGrays(theDialog, numItems, MyVars);
  902.  
  903.         GetDItem(theDialog, numItems + BarDimBox, itemType, itemHandle, dispRect);
  904.         InvalRect(dispRect);
  905.         GetDItem(theDialog, numItems + PieDimBox, itemType, itemHandle, dispRect);
  906.         InvalRect(dispRect);
  907.     end;
  908.  
  909. {This is where we process a hit on one of our controls in the cdev.}
  910.     procedure Hit (theDialog: DialogPtr;
  911.                                     numItems: integer;
  912.                                     MyVars: CDEVVarsH;
  913.                                     item: integer;
  914.                                     var theEvent: EventRecord);    { item has already been offset for us. }
  915.         var
  916.             itemType: integer;
  917.             itemHandle: handle;
  918.             dispRect: rect;
  919.         procedure ArrowStateChange (theDialog: DialogPtr;
  920.                                         itemNumber: integer);
  921.             var
  922.                 theText: str255;
  923.                 aReal: real;
  924.         begin
  925.             GetDItem(theDialog, itemNumber, itemType, itemHandle, dispRect);
  926.             GetIText(itemHandle, theText);
  927.             aReal := GetVal(theText);
  928.             case item of
  929.                 BarLatencyArrows: 
  930.                     begin
  931.                         if MyVars^^.MemVars <> nil then
  932.                             begin
  933.                                 MyVars^^.MemVars^.rsrc.VBLTime := round(aReal * 60);
  934.                                 MyVars^^.MemVars^.VBLRec.VBLCount := 1;                            { Update immediately. }
  935.                             end;
  936.                         MyVars^^.RSRCVars^^.VBLTime := round(aReal * 60);
  937.                     end;
  938.                 BarTickSpaceArrows: 
  939.                     begin
  940.                         if MyVars^^.MemVars <> nil then
  941.                             begin
  942.                                 MyVars^^.MemVars^.rsrc.UnitSize := round(aReal * 1024);
  943.                                 MyVars^^.MemVars^.VBLRec.VBLCount := 1;                            { Update immediately. }
  944.                             end;
  945.                         MyVars^^.RSRCVars^^.UnitSize := round(aReal * 1024);
  946.                     end;
  947.                 PieLatencyArrows: 
  948.                     begin
  949.                         if MyVars^^.MemVars <> nil then
  950.                             begin
  951.                                 MyVars^^.MemVars^.rsrc.PieTime := round(aReal * 60);
  952.                                 MyVars^^.MemVars^.PieNextUpdate := 0;                            { Update immediately. }
  953.                             end;
  954.                         MyVars^^.RSRCVars^^.PieTime := round(aReal * 60);
  955.                     end;
  956.             end;
  957.             ChangedResource(handle(MyVars^^.RSRCVars));
  958.         end;
  959.  
  960.     begin
  961.         GetDItem(theDialog, numItems + item, itemType, itemHandle, dispRect);
  962.         case item of
  963.             BarLatencyArrows, BarTickSpaceArrows, PieLatencyArrows: 
  964.                 if ArrowHit(theDialog, numItems + item, numItems + item - 2, item, theEvent, ArrowStateChange) then
  965.                     WriteResource(handle(MyVars^^.RSRCVars));
  966.             BarColor: 
  967.                 if ColorItemHit(theDialog, numItems + item, MyVars^^.RSRCVars^^.BarColor, 'Bar color:', theEvent) then
  968.                     begin
  969.                         if MyVars^^.MemVars <> nil then
  970.                             begin
  971.                                 MyVars^^.MemVars^.rsrc.BarColor := MyVars^^.RSRCVars^^.BarColor;
  972.                                 MyVars^^.MemVars^.ColorSize := 0;                                    { Force color update. }
  973.                                 WasteEvent;                                                                    { Have our jGNEFilter called, so we'll be updated. }
  974.                                 MyVars^^.MemVars^.VBLRec.VBLCount := 1;                            { Update immediately. }
  975.                             end;
  976.                         ChangedResource(handle(MyVars^^.RSRCVars));
  977.                         WriteResource(handle(MyVars^^.RSRCVars));
  978.                     end;
  979.             ShowIcon: 
  980.                 begin
  981.                     SetCtlValue(ControlHandle(itemHandle), 1 - GetCtlValue(ControlHandle(itemHandle)));
  982.                     if GetCtlValue(ControlHandle(itemHandle)) = 1 then
  983.                         MyVars^^.RSRCVars^^.ShowIcon := sTrue
  984.                     else
  985.                         MyVars^^.RSRCVars^^.ShowIcon := sFalse;
  986.                     ChangedResource(handle(MyVars^^.RSRCVars));
  987.                     WriteResource(handle(MyVars^^.RSRCVars));
  988.                 end;
  989.             BarActive: 
  990.                 begin
  991.                     SetCtlValue(ControlHandle(itemHandle), 1 - GetCtlValue(ControlHandle(itemHandle)));
  992.                     if GetCtlValue(ControlHandle(itemHandle)) = 1 then
  993.                         MyVars^^.RSRCVars^^.VBLActive := sTrue
  994.                     else
  995.                         MyVars^^.RSRCVars^^.VBLActive := sFalse;
  996.                     if MyVars^^.MemVars <> nil then
  997.                         begin
  998.                             MyVars^^.MemVars^.rsrc.VBLActive := MyVars^^.RSRCVars^^.VBLActive;
  999.                             if MyVars^^.MemVars^.rsrc.VBLActive = sFalse then
  1000.                                 DrawMenuBar                { Erase old bar. }
  1001.                             else
  1002.                                 begin
  1003.                                     MyVars^^.MemVars^.ColorSize := 0;                                    { Force color update. }
  1004.                                     WasteEvent;                                                                { Have our jGNEFilter called, so we'll be updated. }
  1005.                                     MyVars^^.MemVars^.VBLRec.VBLCount := 1;                            { Update immediately. }
  1006.                                 end;
  1007.                         end;
  1008.                     ChangedResource(handle(MyVars^^.RSRCVars));
  1009.                     WriteResource(handle(MyVars^^.RSRCVars));
  1010.  
  1011.                     GetDItem(theDialog, numItems + BarSamplePICT, itemType, itemHandle, dispRect);
  1012.                     InvalRect(dispRect);
  1013.  
  1014.                     UpdateGrays(theDialog, numItems, MyVars);
  1015.                 end;
  1016.             PieActive: 
  1017.                 begin
  1018.                     SetCtlValue(ControlHandle(itemHandle), 1 - GetCtlValue(ControlHandle(itemHandle)));
  1019.                     if GetCtlValue(ControlHandle(itemHandle)) = 1 then
  1020.                         MyVars^^.RSRCVars^^.PieActive := sTrue
  1021.                     else
  1022.                         MyVars^^.RSRCVars^^.PieActive := sFalse;
  1023.                     if MyVars^^.MemVars <> nil then
  1024.                         begin
  1025.                             MyVars^^.MemVars^.rsrc.PieActive := MyVars^^.RSRCVars^^.PieActive;
  1026.                             if MyVars^^.MemVars^.rsrc.PieActive = sFalse then
  1027.                                 DrawMenuBar                { Erase old bar. }
  1028.                             else
  1029.                                 begin
  1030.                                     MyVars^^.MemVars^.PieNextUpdate := 0;                            { Update immediately. }
  1031.                                     WasteEvent;                                                                { Have our jGNEFilter called, so we'll be updated. }
  1032.                                 end;
  1033.                         end;
  1034.                     ChangedResource(handle(MyVars^^.RSRCVars));
  1035.                     WriteResource(handle(MyVars^^.RSRCVars));
  1036.  
  1037.                     GetDItem(theDialog, numItems + PieSampleBox, itemType, itemHandle, dispRect);
  1038.                     InvalRect(dispRect);
  1039.  
  1040.                     UpdateGrays(theDialog, numItems, MyVars);
  1041.                 end;
  1042.             PiePieColor: 
  1043.                 if ColorItemHit(theDialog, numItems + item, MyVars^^.RSRCVars^^.PiePieColor, 'Pie color:', theEvent) then
  1044.                     begin
  1045.                         if MyVars^^.MemVars <> nil then
  1046.                             begin
  1047.                                 MyVars^^.MemVars^.rsrc.PiePieColor := MyVars^^.RSRCVars^^.PiePieColor;
  1048.                                 MyVars^^.MemVars^.PieNextUpdate := 0;                                { Update immediately. }
  1049.                                 WasteEvent;                                                                    { Have our jGNEFilter called, so we'll be updated. }
  1050.                             end;
  1051.                         ChangedResource(handle(MyVars^^.RSRCVars));
  1052.                         WriteResource(handle(MyVars^^.RSRCVars));
  1053.                     end;
  1054.             PiePanColor: 
  1055.                 if ColorItemHit(theDialog, numItems + item, MyVars^^.RSRCVars^^.PiePanColor, 'Pie pan color:', theEvent) then
  1056.                     begin
  1057.                         if MyVars^^.MemVars <> nil then
  1058.                             begin
  1059.                                 MyVars^^.MemVars^.rsrc.PiePanColor := MyVars^^.RSRCVars^^.PiePanColor;
  1060.                                 MyVars^^.MemVars^.PieNextUpdate := 0;                                { Update immediately. }
  1061.                                 WasteEvent;                                                                    { Have our jGNEFilter called, so we'll be updated. }
  1062.                             end;
  1063.                         ChangedResource(handle(MyVars^^.RSRCVars));
  1064.                         WriteResource(handle(MyVars^^.RSRCVars));
  1065.                     end;
  1066.             HelpButton: 
  1067.                 DoHelp;
  1068.         end;
  1069.     end;
  1070.  
  1071.     procedure Close (theDialog: DialogPtr;
  1072.                                     numItems: integer;
  1073.                                     var MyVars: CDEVVarsH);
  1074.     begin
  1075.         if Longint(MyVars) > cdevUnset then                { It has to be bigger than this to be a handle. }
  1076.             DisposHandle(handle(MyVars));
  1077.         MyVars := CDEVVarsH(cdevUnset);
  1078.     end;
  1079.  
  1080. {Update - handles update events in the cdev. Much like you would do in a normal application}
  1081. {except that you don't need to call "BeginUpdate" and "EndUpdate".}
  1082.     procedure Update (theDialog: DialogPtr;
  1083.                                     numItems: integer;
  1084.                                     MyVars: CDEVVarsH);
  1085.     begin
  1086.         DrawPICTItem(theDialog, numItems + MemPICTBox);
  1087.  
  1088.         DrawFrameItem(theDialog, numItems + BarLatencyFrame, MyVars);
  1089.         DrawFrameItem(theDialog, numItems + BarTickSpaceFrame, MyVars);
  1090.         DrawFrameItem(theDialog, numItems + PieLatencyFrame, MyVars);
  1091.  
  1092.         DrawBarColorItem(theDialog, numItems + BarColor, MyVars);
  1093.         DrawPiePanColorItem(theDialog, numItems + PiePanColor, MyVars);
  1094.         DrawPiePieColorItem(theDialog, numItems + PiePieColor, MyVars);
  1095.  
  1096.         DrawGrayItem(theDialog, numItems + BarDimBox, MyVars);
  1097.         DrawGrayItem(theDialog, numItems + PieDimBox, MyVars);
  1098.  
  1099.         DrawBarSample(theDialog, numItems + BarSampleBox, MyVars);
  1100.         DrawPieSample(theDialog, numItems + PieSampleBox, MyVars);
  1101.     end;
  1102.  
  1103. {Take action when Control Panel is activated.}
  1104.     procedure Activate (theDialog: DialogPtr;
  1105.                                     numItems: integer;
  1106.                                     MyVars: CDEVVarsH);
  1107.     begin
  1108.     end;
  1109.  
  1110. {Take action when Control Panel is Deactivated.}
  1111.     procedure Deactivate (theDialog: DialogPtr;
  1112.                                     numItems: integer;
  1113.                                     MyVars: CDEVVarsH);
  1114.     begin
  1115.     end;
  1116.  
  1117. {Some time from the system. Use it if you need it. An example use would be calling}
  1118. {TEIdle.}
  1119.     procedure Idle (theDialog: DialogPtr;
  1120.                                     numItems: integer;
  1121.                                     MyVars: CDEVVarsH);
  1122.     begin
  1123.     end;
  1124.  
  1125. {Key - handles key events when the cdev is active. This is where you must have your}
  1126. {command keys (if any) handled as well.}
  1127.     procedure Key (theDialog: DialogPtr;
  1128.                                     numItems: integer;
  1129.                                     MyVars: CDEVVarsH;
  1130.                                     event: EventRecord);
  1131.         var
  1132.             ch: char;        {To get the character pressed}
  1133.     begin
  1134.         if event.what <> autoKey then        {If its not an autoKey event}
  1135.             begin
  1136.                 if BitAnd(event.modifiers, CmdKey) <> 0 then            {Is the Command Key down?}
  1137.                     ch := chr(BitAnd(event.message, charCodeMask));        {Convert to char}
  1138.                 case ch of                                                    {Case it}
  1139.                     'z', 'Z':                         {These are the standard Edit Cmd Keys}
  1140.                         SysBeep(1);                {Add yours in below}
  1141.                     'x', 'X': 
  1142.                         SysBeep(1);
  1143.                     'c', 'C': 
  1144.                         SysBeep(1);
  1145.                     'v', 'V': 
  1146.                         SysBeep(1);
  1147.                 end;
  1148.             end;
  1149.     end;
  1150.  
  1151. {This is our main routine}
  1152.     function main (message, item, numItems, CPid: integer;
  1153.                                     event: EventRecord;
  1154.                                     cdevValue: Longint;
  1155.                                     dlg: DialogPtr): Longint;
  1156.     begin
  1157.         if cdevValue > cdevUnset then                { It has to be bigger than this to be a handle. }
  1158.             begin
  1159.                 HLock(handle(cdevValue));
  1160.                 HLock(handle(CDEVVarsH(cdevValue)^^.RSRCVars));
  1161.             end;
  1162.         case message of
  1163.             initDev: 
  1164.                 cdevValue := longint(InitItems(dlg, numItems));
  1165.             hitDev: 
  1166.                 Hit(dlg, numItems, CDEVVarsH(cdevValue), item - numItems, event);
  1167.             closeDev: 
  1168.                 Close(dlg, numItems, CDEVVarsH(cdevValue));
  1169.             nulDev: 
  1170.                 Idle(dlg, numItems, CDEVVarsH(cdevValue));
  1171.             updateDev: 
  1172.                 Update(dlg, numItems, CDEVVarsH(cdevValue));
  1173.             activDev: 
  1174.                 Activate(dlg, numItems, CDEVVarsH(cdevValue));
  1175.             deactivDev: 
  1176.                 Deactivate(dlg, numItems, CDEVVarsH(cdevValue));
  1177.             keyEvtDev: 
  1178.                 Key(dlg, numItems, CDEVVarsH(cdevValue), event);
  1179.             undoDev: 
  1180.                 sysBeep(1);
  1181.             cutDev: 
  1182.                 sysBeep(1);
  1183.             copyDev: 
  1184.                 sysBeep(1);
  1185.             pasteDev: 
  1186.                 sysBeep(1);
  1187.             clearDev: 
  1188.                 sysBeep(1);
  1189.         end;
  1190.         if cdevValue > cdevUnset then                { It has to be bigger than this to be a handle. }
  1191.             begin
  1192.                 HUnLock(handle(cdevValue));
  1193.                 HLock(handle(CDEVVarsH(cdevValue)^^.RSRCVars));
  1194.             end;
  1195.         main := cdevValue;
  1196.     end;
  1197.  
  1198. end.